package logic

import (
	"context"
	"goods_srv/goods"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.GoodsListRequest) (resp *types.RegMsgResponse, err error) {
	// todo: 商品列表

	list, err := l.svcCtx.GoodsSrv.GoodsList(l.ctx, &goods.GoodsListRequest{
		Keyword:  req.Keyword,
		Page:     req.Page,
		PageSize: req.PageSize,
	})
	if err != nil {
		return &types.RegMsgResponse{
			Cre:  -1,
			Msg:  "服务器错误",
			Data: nil,
		}, err
	}
	return &types.RegMsgResponse{
		Cre: 0,
		Msg: "展示列表",
		Data: map[string]interface{}{
			"list": list.GoodsList,
		},
	}, err
}
